﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>友情链接 </title>
    <link href="../static/css/admin.css?v=6" rel="stylesheet" />
    <script src="../static/js/boot.js?v=2"></script>
    <script src="../static/js/admin.js?v=2"></script>
    <script>
        var apiUrl = API_PATH + "/Friendlink/";
        var keyValue = $.request("keyValue");
        $(function () {
            initControl();
            console.log(keyValue);
            if (!!keyValue) {
                $.ajax({
                    url: apiUrl + "GetFormJson?keyId=" + keyValue,
                    data: { keyValue: keyValue },
                    dataType: "json",
                    async: false,
                    beforeSend: function (jqXHR) {
                        jqXHR.setRequestHeader("Authorization", 'Bearer ' + window.LS.get("hdjtoken"));
                    },
                    success: function (ret) {
                        $("#form1").formSerialize(ret);

                        $("#Icon").val("/upfile/" + ret.Icon);
                        $("#headPic").attr('src', "/upfile/" + ret.Icon);
                    }
                });
            }
        })
        function initControl() {
            $("#AddTime").val(new Date().Format('yyyy-MM-dd hh:mm:ss'));
            UploadPic();
        }

        function submitForm() {
            if (!$('#form1').formValid()) {
                return false;
            }
            var aurl = apiUrl + "SubmitForm";
            var paramform = $("#form1").formSerialize();
            paramform["Status"] = $("input[name='Status']:checked").val();
            $.submitForm({
                url: aurl,
                param: paramform,
                paramType: true,
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            })
        }
        function UploadPic() {
            let fil = document.querySelector('#file1')
            let headPic = document.querySelector('#headPic')
            headPic.addEventListener('click', function () {
                fil.click()
            });
            //头像上传
            fil.addEventListener('change', function (e) {
                var formData = new FormData();
                formData.append('files', $("#file1")[0].files[0]);  /*获取上传的图片对象*/
                $.ajax({
                    url: API_PATH + '/File/Upload',
                    type: 'POST',
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (args) {
                        var json2 = eval("(" + args + ")");
                        console.log(json2);
                        $("#headPic").attr('src', "/upfile/" + json2[0]);
                        $("#Icon").val(json2[0]);
                    }
                })
            })
        }
    </script>
</head>
<body style="margin:0px;padding:0px;overflow:hidden;">
    <form id="form1">
        <div style="margin-top: 10px; margin-left: 10px; margin-right: 10px;">
            <div style="padding-top: 20px; margin-right: 30px;">
                <input type="hidden" id="ID" name="ID" value="" />
                <input type="hidden" id="AddTime" name="AddTime" value="" />
                <input type="hidden" id="OrderBy" name="OrderBy" value="" />
                <input type="hidden" id="Icon" name="Icon" />
                <input type="hidden" id="Category" name="Category" value="" />
                <table class="form">
                    <tr>
                        <th class="formTitle">名称<span style="color:#ff0000">*</span></th>
                        <td class="formValue">
                            <input id="Name" name="Name" type="text" class="form-control required" autocomplete="off" maxlength="200" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">Url<span style="color:#ff0000">*</span></th>
                        <td class="formValue">
                            <input id="Url" name="Url" type="text" class="form-control required" autocomplete="off" maxlength="200" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">图标</th>
                        <td class="formValue">
                            <div class="form-group" style="margin-bottom:0px;">
                                <div>
                                    <img id="headPic" src=" ../static/img/jiahao.png" style="width:64px;height:64px;" onerror="this.src=' ../static/img/jiahao.png'" />
                                    <input type="file" id="file1" name="file1" style="display:none;" />
                                </div>

                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">描述</th>
                        <td class="formValue">
                            <textarea id="Description" name="Description" class="form-control" rows="6" style="width: 100%;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">是否可用<span style="color:#ff0000"></span></th>
                        <td class="formValue">
                            <input id="Status" name="Status" type="checkbox" checked="checked" value="1" /><label for="Status">启用</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">排序</th>
                        <td class="formValue">
                            <input id="OrderBy" name="OrderBy" type="number" value="1" class="form-control" autocomplete="off" maxlength="200" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </form>
</body>
</html>